//
//  MusicAudioPlayerTool.m
//  Gegeda_music_MY
//
//  Created by lanou3g on 15/11/11.
//  Copyright © 2015年 周莹. All rights reserved.
//

#import "MusicAudioPlayerTool.h"

static NSMutableDictionary  *musicPlayAudioDict;

@implementation MusicAudioPlayerTool

+(NSMutableDictionary *)musicPlayAudioDict{

    if (!musicPlayAudioDict) {
        musicPlayAudioDict = [NSMutableDictionary dictionary];
    }
    return musicPlayAudioDict;

}
#pragma mark 根据url 播放音乐
+(AVPlayer *)playMusicWithMusicurlString:(NSString *)musicurlString{

    if (musicurlString  == nil) {
        NSLog(@"无效的播放路径");
        return nil;
    }
//从字典取出播放器
    AVPlayer *player = [self  musicPlayAudioDict][musicurlString];
    //判断字典里面取出的播放器是否为空
    if (player == nil) {
        //创建新的播放器
        player = [[AVPlayer  alloc]initWithURL:[NSURL  URLWithString:musicurlString]];
        //把播放器添加到字典
        [[self musicPlayAudioDict]setObject:player forKey:musicurlString];
        
        
    }
    [player play];
    return player;
    

}

#pragma mark 根据音乐url停止播放音乐
+(void)stopMusicWithMusicUrlstring:(NSString *)muiscString{
    if (muiscString   == nil) {
        return;
    }
    AVPlayer *player = [self  musicPlayAudioDict][muiscString];
    //暂停
    [player pause];
    [[self musicPlayAudioDict]removeObjectForKey:muiscString];
    player = nil;


}






@end
